{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fe5d9080",
   "metadata": {},
   "source": [
    "# 数组的组合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "id": "e4cd2f34",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "id": "26e160c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.arange(6).reshape(3,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "id": "a22c399d",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr2 = np.arange(6,12).reshape(3,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "id": "a70138b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1],\n",
       "       [2, 3],\n",
       "       [4, 5]])"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "id": "3aae8eb3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 6,  7],\n",
       "       [ 8,  9],\n",
       "       [10, 11]])"
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "id": "b33abde7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1],\n",
       "       [ 2,  3],\n",
       "       [ 4,  5],\n",
       "       [ 6,  7],\n",
       "       [ 8,  9],\n",
       "       [10, 11]])"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack((arr1,arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "id": "418a2d86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  6,  7],\n",
       "       [ 2,  3,  8,  9],\n",
       "       [ 4,  5, 10, 11]])"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hstack((arr1,arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "id": "df4e1d7f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1],\n",
       "       [ 2,  3],\n",
       "       [ 4,  5],\n",
       "       [ 6,  7],\n",
       "       [ 8,  9],\n",
       "       [10, 11]])"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.concatenate((arr1,arr2),axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "id": "58a69db4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  6,  7],\n",
       "       [ 2,  3,  8,  9],\n",
       "       [ 4,  5, 10, 11]])"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.concatenate((arr1,arr2),axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "436aa63f",
   "metadata": {},
   "source": [
    "# 数组拆分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "id": "4c2a0d42",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr4 = np.arange(24).reshape(6,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "id": "9e963296",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[ 0,  1],\n",
       "        [ 4,  5],\n",
       "        [ 8,  9],\n",
       "        [12, 13],\n",
       "        [16, 17],\n",
       "        [20, 21]]),\n",
       " array([[ 2,  3],\n",
       "        [ 6,  7],\n",
       "        [10, 11],\n",
       "        [14, 15],\n",
       "        [18, 19],\n",
       "        [22, 23]])]"
      ]
     },
     "execution_count": 193,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hsplit(arr4,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "id": "f305afff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[ 0,  1,  2,  3],\n",
       "        [ 4,  5,  6,  7],\n",
       "        [ 8,  9, 10, 11]]),\n",
       " array([[12, 13, 14, 15],\n",
       "        [16, 17, 18, 19],\n",
       "        [20, 21, 22, 23]])]"
      ]
     },
     "execution_count": 194,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vsplit(arr4,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "id": "299f8e2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[ 0,  1,  2,  3],\n",
       "        [ 4,  5,  6,  7],\n",
       "        [ 8,  9, 10, 11]]),\n",
       " array([[12, 13, 14, 15],\n",
       "        [16, 17, 18, 19]]),\n",
       " array([[20, 21, 22, 23]])]"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vsplit(arr4,[3,5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "id": "f57760f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[ 0,  1,  2,  3],\n",
       "        [ 4,  5,  6,  7],\n",
       "        [ 8,  9, 10, 11]]),\n",
       " array([[12, 13, 14, 15],\n",
       "        [16, 17, 18, 19],\n",
       "        [20, 21, 22, 23]])]"
      ]
     },
     "execution_count": 196,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.split(arr4,2,axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "id": "06bc55b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[ 0,  1],\n",
       "        [ 4,  5],\n",
       "        [ 8,  9],\n",
       "        [12, 13],\n",
       "        [16, 17],\n",
       "        [20, 21]]),\n",
       " array([[ 2,  3],\n",
       "        [ 6,  7],\n",
       "        [10, 11],\n",
       "        [14, 15],\n",
       "        [18, 19],\n",
       "        [22, 23]])]"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.split(arr4,2,axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4585723",
   "metadata": {},
   "source": [
    "# 一元数学函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "id": "beda77aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr5 = np.random.randn(3,3)+np.random.randint(16,size=(3,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "id": "3045a8e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[12.30297081, 12.37141229,  2.55367246],\n",
       "       [13.532052  ,  1.21891969, 12.66507419],\n",
       "       [11.20854959,  5.06096155, 10.20220213]])"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "id": "71453d6f",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr6,arr7=np.modf(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "id": "40c80e3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.30297081, 0.37141229, 0.55367246],\n",
       "       [0.532052  , 0.21891969, 0.66507419],\n",
       "       [0.20854959, 0.06096155, 0.20220213]])"
      ]
     },
     "execution_count": 201,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "id": "b58bf124",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[12., 12.,  2.],\n",
       "       [13.,  1., 12.],\n",
       "       [11.,  5., 10.]])"
      ]
     },
     "execution_count": 202,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "id": "7569c893",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[151.36309069, 153.05184209,   6.52124302],\n",
       "       [183.11643126,   1.48576522, 160.40410414],\n",
       "       [125.63158389,  25.61333183, 104.08492832]])"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.square(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "id": "978aa29e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3.5075591 , 3.51730185, 1.59802142],\n",
       "       [3.67859375, 1.10404696, 3.55880235],\n",
       "       [3.3479172 , 2.2496581 , 3.19408862]])"
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "id": "c7bb1971",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.20349634e+05, 2.35958753e+05, 1.28542238e+01],\n",
       "       [7.53174333e+05, 3.38353051e+00, 3.16498628e+05],\n",
       "       [7.37583575e+04, 1.57742121e+02, 2.69624957e+04]])"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.exp(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "id": "23723de5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [1., 1., 1.],\n",
       "       [1., 1., 1.]])"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sign(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "id": "5325b22d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[13., 13.,  3.],\n",
       "       [14.,  2., 13.],\n",
       "       [12.,  6., 11.]])"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ceil(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "id": "793e12c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[12., 12.,  2.],\n",
       "       [13.,  1., 12.],\n",
       "       [11.,  5., 10.]])"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.floor(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "id": "c03e0af3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[12., 12.,  3.],\n",
       "       [14.,  1., 13.],\n",
       "       [11.,  5., 10.]])"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.rint(arr5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcf8cb91",
   "metadata": {},
   "source": [
    "# 二元函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "id": "308bdd55",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr6 = arr6*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "id": "f100e290",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[15.02970808, 15.71412291,  7.53672457],\n",
       "       [18.32051997,  3.18919694, 18.65074186],\n",
       "       [13.08549589,  5.60961552, 12.02202131]])"
      ]
     },
     "execution_count": 211,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.add(arr6,arr7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "id": "45887ed0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-8.97029192, -8.28587709,  3.53672457],\n",
       "       [-7.67948003,  1.18919694, -5.34925814],\n",
       "       [-8.91450411, -4.39038448, -7.97797869]])"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.subtract(arr6,arr7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "1b082f0c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[36.35649691, 44.56947498, 11.07344914],\n",
       "       [69.16675965,  2.18919694, 79.80890236],\n",
       "       [22.94045482,  3.0480776 , 20.22021309]])"
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.multiply(arr6,arr7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "id": "e5076f2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.25247567, 0.30951024, 2.76836229],\n",
       "       [0.40927077, 2.18919694, 0.55422849],\n",
       "       [0.18959054, 0.1219231 , 0.20220213]])"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.divide(arr6,arr7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "id": "9aee9b1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5.98149047e+05, 6.89088918e+06, 3.06553190e+01],\n",
       "       [2.73780815e+09, 2.18919694e+00, 7.48929782e+09],\n",
       "       [3.24565778e+03, 8.41937932e-02, 1.14250282e+03]])"
      ]
     },
     "execution_count": 215,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.power(arr6,arr7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "id": "a7951d1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True,  True,  True],\n",
       "       [ True,  True,  True],\n",
       "       [ True,  True,  True]])"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.greater(arr5,np.sqrt(arr5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "id": "3324fb2b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True,  True,  True],\n",
       "       [ True,  True,  True],\n",
       "       [ True,  True,  True]])"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.greater_equal(arr5,np.sqrt(arr5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "d0a99f44",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True,  True,  True],\n",
       "       [ True,  True,  True],\n",
       "       [ True,  True,  True]])"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.logical_and(arr6>0,arr7>0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05a3fb6d",
   "metadata": {},
   "source": [
    "# 文件读写操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "id": "99cbee88",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.arange(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "id": "d0aa248a",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.save('arr1',arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "id": "662ba4ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.load('arr1.npy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "ad0d2a9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr2=np.arange(6,12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "id": "460d9b08",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.savez('arr',a=arr1,b=arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "id": "403ecc4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr=np.load('arr.npz')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "id": "b97771a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<numpy.lib.npyio.NpzFile at 0x15a182e0090>"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "id": "cf02ae74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr['a']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "id": "5e0a4148",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6,  7,  8,  9, 10, 11])"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr['b']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "id": "980cb0ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr=np.stack([arr1,arr2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "id": "4d0b2e5a",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.savetxt(\"arr.txt\",arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "id": "49f95ed0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.,  1.,  2.,  3.,  4.,  5.],\n",
       "       [ 6.,  7.,  8.,  9., 10., 11.]])"
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.loadtxt(\"arr.txt\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dcf8926f",
   "metadata": {},
   "source": [
    "# 排序与条件筛选"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "id": "931863d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr3 = np.array([[1,3,5],[4,2,6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "id": "5f87ad94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 5],\n",
       "       [4, 3, 6]])"
      ]
     },
     "execution_count": 232,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(arr3,axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "id": "a92034cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 3, 5],\n",
       "       [2, 4, 6]])"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(arr3,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 234,
   "id": "17620264",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.random.randint(0,11,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "id": "5c05bf09",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 8,  7,  0,  3,  6,  6,  3, 10,  1,  6])"
      ]
     },
     "execution_count": 235,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 236,
   "id": "efa930f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 236,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(a)[int(0.8*len(a))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 237,
   "id": "6df2efc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 8, 3, 6, 4, 5, 9, 1, 0, 7], dtype=int64)"
      ]
     },
     "execution_count": 237,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.argsort(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 238,
   "id": "e2eb9c59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  3,  3,  6,  6,  6,  7,  8, 10])"
      ]
     },
     "execution_count": 238,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[np.argsort(a)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "id": "3e39fc26",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = np.array([1,1,1,0,0,0,2,2,2,2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 240,
   "id": "dc4c036f",
   "metadata": {},
   "outputs": [],
   "source": [
    "index = np.lexsort((a,b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "id": "cf167997",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 4, 5, 2, 1, 0, 8, 6, 9, 7], dtype=int64)"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 242,
   "id": "a5124e75",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  3],\n",
       "       [ 0,  6],\n",
       "       [ 0,  6],\n",
       "       [ 1,  0],\n",
       "       [ 1,  7],\n",
       "       [ 1,  8],\n",
       "       [ 2,  1],\n",
       "       [ 2,  3],\n",
       "       [ 2,  6],\n",
       "       [ 2, 10]])"
      ]
     },
     "execution_count": 242,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.hstack((b[index].reshape(10,1),a[index].reshape(10,1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "id": "99676efc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 8,  7,  6,  6, 10,  6])"
      ]
     },
     "execution_count": 243,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.extract(a>5,a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 244,
   "id": "494d7832",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([0, 1, 4, 5, 7, 9], dtype=int64),)"
      ]
     },
     "execution_count": 244,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.where(a>5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 245,
   "id": "43a5a0e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 8,  7,  6,  6, 10,  6])"
      ]
     },
     "execution_count": 245,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[np.where(a>5)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 246,
   "id": "63ed9eae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 8,  7,  0,  0,  6,  6,  0, 10,  0,  6])"
      ]
     },
     "execution_count": 246,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.where(a>5,a,0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
